home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / begincpp.zip / #7_VER2.CPP < prev    next >
Text File  |  1990-08-03  |  648b  |  41 lines

  1. void *malloc(unsigned);
  2. int free (void *);
  3.  
  4. struct tag_name {    //tag_name is also a type in C++
  5.     int   i;
  6.     float f;
  7. };
  8.  
  9. class class_one {
  10.     tag_name t;    //implicitly declare class_one *this;
  11.   public:
  12.     class_one (int i0 = 0, float f0 = 0) { t.i = i0, t.f = f0; }
  13.     class_one *tag() { return this; }
  14. };
  15.  
  16. class class_two {
  17.   public:
  18.     class_two (unsigned);
  19.     ~class_two();
  20. };
  21.  
  22. class_two::class_two (unsigned size) 
  23.     this = (class_two *) malloc (size); 
  24. }
  25.  
  26. class_two::~class_two ()
  27.     free (this); 
  28.     this = 0; 
  29. }
  30.  
  31.  
  32. main() 
  33. {
  34.     class_one c1 (1, 1.1), cc1;
  35.     class_two c2 (sizeof(class_two)) ;
  36.  
  37.     cc1 = *c1.tag();
  38. }
  39.